public class Spaceship extends Entity
{
  public boolean isDead;
  private PShape ps;
  public int lifes;

  public int cannonPos; //Orientation du cannon

  public Spaceship(int xpos, int ypos, AnimationContext context)
  {
    this.xpos = xpos;
    this.ypos = ypos;
    this.renderSizeX = 40;
    this.renderSizeY = 40;

    this.lifes = context.lives;
    this.isDead = false;
    this.ps = loadShape("spaceship.svg");

    this.cannonPos = 0; //Par défaut, le canon est en position neutre (tir droit devant)
  }

  public void updatePosition()
  {

    if (mouseX < 0)
    {
      xpos = 0;
    }
    else if (mouseX > width - renderSizeX)
    {
      xpos = width - renderSizeX;
    }
    else
    {
      xpos = mouseX;
    }
  }

  public void updatePosition(AnimationContext context)
  {
    xpos = context.XpositionGlobalSpaceShip;
  }


  public void display()
  {
    //Orientation du cannon/viseur
    int xinit = this.xpos + 19;
    int yinit = this.ypos;

    strokeWeight(10);
    stroke(#830628);
    line(xinit, yinit+5, xinit+this.cannonPos, yinit-3);
    noStroke();

    //fin orientation du canon

    shape(ps, xpos, ypos, renderSizeX, renderSizeY);
  }

  public boolean isOutsideZone()
  {
    return false;
  }

  void removeLife()
  {
    if (lifes > 0)
    {
      lifes--;
    }

    isDead = lifes <= 0;
  }
}

